function smallerNumbersThanCurrent(nums: number[]) {
  const map = new Map<number, number>()
  const sorted = [...nums].sort((a, b) => a - b)
  const len = sorted.length
  let pre = -Infinity
  for (let i = 0; i < len; i += 1) {
    if (sorted[i] > pre) {
      map.set(sorted[i], i)
      pre = sorted[i]
    }
  }
  return nums.map((one) => map.get(one))
}

export { smallerNumbersThanCurrent }
